<?php

class Model_ToFgBlog extends Model {

    function __construct() {
        
    }

    function get_blog($h_param = array()) {
        //$result = array();

        $id = intval($h_param['id']) ? intval($h_param['id']) : 0;
        $page = 1;
        $size = 10;

        $where = "TB1.status=1 and TB1.is_blog=1 and TB1.is_publish=1";
        if ($id)
            $where .=" and TB1.id=" . $id;
        $db = 'product_reports';
        $group = "";
        $orderby = "TB1.addtime desc,TB1.id desc";
        if (intval($id) == 0) {
            $group = "TB1.mid";
            $db = "(select * from product_reports order by addtime desc)";
        }


        $param = array();
        $param['field'] = "TB1.id,TB1.mid,TB1.title,TB1.body,(TB1.likes+TB1.likes_num_base) AS likes,TB1.status,TB1.addtime,TB1.is_publish,TB2.photo,TB2.username,TB1.is_blog,(TB1.click+TB1.click_base_num) as click,TB1.lastmodify";
        $param['where'] = $where;
        $param['order'] = $orderby; //"id asc"
        $param['group'] = $group;
        $param['limit'] = "";
        $param['pagesize'] = $size;
        $param['page'] = $page;
        $param['join'] = "LEFT JOIN member_imore";
        $param['on'] = "TB1.mid = TB2.id";
        $data = db_query_hash($db, $param);
        $result = array();
        if ($data['result']) {
            foreach ($data['result'] as $key => $value) {

                $value['avatar'] = imore_avatar($value['photo']);
                $value['body'] = htmlspecialchars_decode($value['body']);
                unset($value['photo']);
                $result[$key] = $value;
            }
        }

        return $result;
    }

}

?>